package com.yd.app.mapper;

import com.yd.app.mapper.provider.NoticeProvider;
import com.yd.domain.business.Notice;
import com.yd.domain.searchParam.NoticeParam;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zy
 * @create  2018-03-09 14:05
 * @desc 公告mapper
 **/
@Repository
public interface NoticeMapper {
    /**
     * @Author: zy
     * @Desc: 数据录入
     * @Date:  2018/3/9
     * @Param
     */
    @Insert("INSERT INTO business_notice (id,status,title,des,publishTime,publishUser)" +
            " VALUES(#{n.id},#{n.status},#{n.title},#{n.des},#{n.publishTime},#{n.publishUser})")
    void addNotice(@Param("n")Notice n);
    /**
     * @Author: zy
     * @Desc: 修改数据
     * @Date:  2018/3/9
     * @Param
     */
    @Update("update business_notice set `status`=#{n.status},title=#{n.title},des=#{n.des} where id=#{n.id}")
    void updateNotice(@Param("n")Notice n);
   /**
    * @Author: zy
    * @Desc: 根据id删除
    * @Date:  2018/3/9
    * @Param
    */
    @Delete("delete from business_notice where id=#{id}")
    void deleteNotice(@Param("id") String id);
   /**
    * @Author: zy
    * @Desc: 根据id查询
    * @Date:  2018/3/9
    * @Param
    */
    @Select("SELECT n.id,n.`status`,n.title,n.des,n.publishTime,n.publishUser from business_notice n  WHERE n.id=#{id}")
    Notice findById(@Param("id") String id);
    /**
     * @Author: zy
     * @Desc: 审核状态
     * @Date:  2018/3/9
     * @Param
     */
    @Update("update business_notice set `status`=#{n.status} where id=#{n.id}")
    void verifyNotice(@Param("n")Notice n);
   /**
    * @Author: zy
    * @Desc: 分页查询
    * @Date:  2018/3/9
    * @Param
    */
    @SelectProvider(method = "searchNoticeList",type= NoticeProvider.class)
    List<Notice> searchNoticeList(@Param("noticeParam") NoticeParam noticeParam, @Param("startRow") int startRow, @Param("pageSize") int pageSize);
    /**
     * @Author: zy
     * @Desc:查询数量
     * @Date:  2018/3/9
     */
    @SelectProvider(method = "searchNoticeCount",type= NoticeProvider.class)
    int searchNoticeCount(@Param("noticeParam") NoticeParam noticeParam);

    @Select("select * from business_notice order by publishTime desc limit 1 ")
    Notice getNotice();

    //启用公告
    @Update("update business_notice set status='1' where id=#{noticeId} ")
    void enableNotice(@Param("noticeId") String noticeId);

    @Update("update business_notice set status=#{s} ")
    void updateNoticeStatus(@Param("s") String s);
    //查询公告
    @Select("select * from business_notice where id=#{noticeId} ")
    Notice getNoticeById(@Param("noticeId") String noticeId);
}
